package com.cncytech.uiautomator_demo.testcase;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.util.Log;

import com.cncytech.uiautomator_demo.BaseTest;
import com.cncytech.uiautomator_demo.RetryWatcher;
import com.cncytech.uiautomator_demo.TestConstant;
import com.cncytech.uiautomator_demo.utils.Describe;

import org.junit.Rule;
import org.junit.Test;

import java.util.List;

/**
 * wifi测试
 */


public class WLANTest extends BaseTest {

    private static final String TAG = "HardwareModuleControlTest";
    @Rule
    public RetryWatcher retryWatcher = new RetryWatcher(TestConstant.retryCount);

    @Test
    @Describe(TestConstant.WLAN_FORBIDDEN)
    public void WlanOffTest()   {
        String s = "wlan 关闭失败";
        int status = 0;
        //方法调用成功
        assertThat(s, hmm.setWlanPolicies(status));

        int wlanPolicies = hmm.getWlanPolicies();
        Log.i(TAG, "WlanOffTest: " + wlanPolicies);
        //状态一致
        assertThat(s, wlanPolicies, is(status));

      /*  //断言 wlan开关已经禁用
        settingPage.lanchSettingApp();
        settingPage.OpenWlanSetting();
        boolean enabled = settingPage.findPower().isEnabled();
        assertThat("wlan禁用失败", enabled, is(false));*/
    }

    @Test
    @Describe(TestConstant.WLAN_SCAN)
    public void WlanOnTest()   {
        String s = "wlan 开启失败";
        int status = 1;
        setUp();
        //方法调用成功
        assertThat(s, hmm.setWlanPolicies(status));
        int result = hmm.getWlanPolicies();
        Log.i(TAG, "WlanOnTest: result " + result);
        //状态一致
        assertThat(s, result, is(status));


       // assertThat("未扫描到可用wifi", results.size(), not(is(0)));

        //断言 wlan开关已经禁用
      /*  settingPage.lanchSettingApp();
        settingPage.OpenWlanSetting();
        boolean enabled = settingPage.findPower().isEnabled();
        assertThat("wlan开启失败", enabled, is(true));*/


    }

    public void checkWifiSize(){
        WifiManager wifiManager = (WifiManager) applicationContext.getSystemService(Context.WIFI_SERVICE);
        List<ScanResult> results = wifiManager.getScanResults();
        StringBuffer bs = new StringBuffer();
        results.forEach(e -> bs.append(e.SSID + "\t"));
        Log.i(TAG, "WlanOnTest: scan reslut count = " + results.size() + bs.toString());
    }
}
